{{include file="public/header.php"/}}

<ol class="breadcrumb">
    <li>
        <span class="glyphicon glyphicon-home"></span>
        <a href="{{U('Cms/Index/welcome')}}">首页</a>
    </li>
    <li>添加字段</li>
</ol>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <div class="alert alert-success" style="border:solid 1px #27ae60;">
                请仔细填写
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="main-box">
                <header class="main-box-header clearfix">
                    <h2>添加字段</h2>
                </header>
                <div class="main-box-body clearfix ">
                    <form class="form-horizontal" role="form" onsubmit="return update();">
                        <input type="hidden" name="fid" value="{{$field['fid']}}">
                        <input type="hidden" name="mid" value="{{$field['mid']}}">
                        <input type="hidden" name="_method" value="PUT">
                        <table class="table table-bordered ">
                            <tr>
                                <th class="col-lg-4 text-right ">模型</th>
                                <td>
                                    {{$field['model_name']}}
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right ">表<br/><small>字段所在表</small>
                                </th>
                                <td>
                                    {{$field['table_name']}}
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">字段标题<br/><small>例如：文章标题</small></th>
                                <td>
                                    <label class="col-lg-4">
                                        <input type="text" value="{{$field['title']}}" class="form-control input-sm" name="title">
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">字段名<br/><small>必须为英文小写字母</small></th>
                                <td>
                                    <div class="col-lg-4">
                                        {{$field['field_name']}}
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">字段提示</th>
                                <td>
                                    <div class="col-lg-8">
                                        <textarea name="tips" class="form-control" rows="5">{{$field['tips']}}</textarea>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">参数</th>
                                <td>
                                    <?php require VIEW_PATH.'/Field/View/'.$field['field_type'].'/edit.php'?>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">表单样式名<br/><small>定义表单的CSS样式名</small></th>
                                <td>
                                    <div class="col-lg-5">
                                        <input type="text" value="{{$field['css']}}" class="form-control input-sm" name="css">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">字符长度取值范围
                                    <br/><small>系统将在表单提交时检测数据长度范围，如果不想限制长度请留空</small>
                                </th>
                                <td class="form-horizontal">
                                    <div class="form-group">
                                        <label for="" class="col-lg-1 text-right">
                                            最小值:
                                        </label>
                                        <div class="col-lg-2">
                                            <input type="text" value="{{$field['minlength']}}" class="form-control input-sm" name="minlength">
                                        </div>
                                        <label for="" class="col-lg-1 text-right">
                                            最大值:
                                        </label>
                                        <div class="col-sm-2">
                                            <input type="text" value="{{$field['maxlength']}}" class="form-control input-sm" name="maxlength">
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">表单验证
                                    <br/><small>系统将通过此正则校验表单提交的数据合法性，如果不想校验数据请留空</small>
                                </th>
                                <td>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control input-sm" value="{{$field['validate']}}" name="validate">
                                    </div>
                                    <div class="col-sm-2">
                                        <select id="field_check" class="form-control input-sm">
                                            <option value="">常用正则</option>
                                            <option value="/^[0-9.-]+$/">数字</option>
                                            <option value="/^[0-9-]+$/">整数</option>
                                            <option value="/^[a-z]+$/i">字母</option>
                                            <option value="/^[0-9a-z]+$/i">数字+字母</option>
                                            <option value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
                                            <option value="/^[0-9]{5,20}$/">QQ</option>
                                            <option value="/^http:\/\//">超级链接</option>
                                            <option value="/^(1)[0-9]{10}$/">手机号码</option>
                                            <option value="/^[0-9-]{6,13}$/">电话号码</option>
                                            <option value="/^[0-9]{6}$/">邮政编码</option>
                                        </select>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">必须输入
                                </th>
                                <td>
                                    <label>
                                        <input type="radio" name="required" value="1" {{if value="$field['required']==1"}}checked{{/if}}> 是
                                    </label>
                                    <label>
                                        <input type="radio" name="required" value="0" {{if value="$field['required']==0"}}checked{{/if}}> 否
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">错误提示<br/>
                                    <small>输入内容不正确时的提示信息</small>
                                </th>
                                <td>
                                    <div class="col-lg-5">
                                        <input type="text" class="form-control input-sm" name="error" value="{{$field['error']}}">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">值唯一</th>
                                <td>
                                    <label>
                                        <input type="radio" name="isunique" value="1" {{if value="$field['isunique']==1"}}checked{{/if}}> 是
                                    </label>
                                    <label>
                                        <input type="radio" name="isunique" value="0" {{if value="$field['isunique']==0"}}checked{{/if}}> 否
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">作为基本信息</th>
                                <td>
                                    <label>
                                        <input type="radio" name="isbase" value="1" {{if value="$field['isbase']==1"}}checked{{/if}}> 是
                                    </label>
                                    <label>
                                        <input type="radio" name="isbase" value="0" {{if value="$field['isbase']==0"}}checked{{/if}}> 否
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">作为搜索条件</th>
                                <td>
                                    <label>
                                        <input type="radio" name="issearch" value="1" {{if value="$field['issearch']==1"}}checked{{/if}}> 是
                                    </label>
                                    <label>
                                        <input type="radio" name="issearch" value="0" {{if value="$field['issearch']==0"}}checked{{/if}}> 否
                                    </label>
                                </td>
                            </tr>
                            <tr>
                                <th class="text-right">在前台投稿中显示</th>
                                <td>
                                    <label>
                                        <input type="radio" name="isadd" value="1" {{if value="$field['isadd']==1"}}checked{{/if}}> 是
                                    </label>
                                    <label>
                                        <input type="radio" name="isadd" value="0" {{if value="$field['isadd']==0"}}checked{{/if}}> 否
                                    </label>
                                </td>
                            </tr>
                        </table>
                        <div class="col-lg-offset-4">
                            <input type="submit" class="btn btn-primary" value="更新字段">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{{include file="public/footer.php"/}}
<style type="text/css">
    small{color:#999;}
    th{
        background: #f9f9f9;
    }
    td{
        background: #f3f3f3;
    }
</style>
<script>
    function update()
    {
        $.ajax({
            url:"/cms/field/{{$field['fid']}}",
            data:$('form').serialize(),
            type:'POST',
            dataType:'JSON',
            success:function(result)
            {
                if(result.code==0)
                {
                    dialog(result.message,'success',1000,function()
                    {
                        location.href="/cms/field?mid={{$field['mid']}}"
                    });
                }
                else
                {
                    dialog(result.message,'error',1000);    
                }
            }
        })
        return false;
    }
</script>